﻿using System;
using Spline;
using UnityEngine;

// Token: 0x02000206 RID: 518
public class AutoMode
{
	// Token: 0x17000172 RID: 370
	// (get) Token: 0x06000E26 RID: 3622 RVA: 0x00058890 File Offset: 0x00056A90
	// (set) Token: 0x06000E27 RID: 3623 RVA: 0x00058898 File Offset: 0x00056A98
	public Vector2 nowPos { get; private set; }

	// Token: 0x06000E28 RID: 3624 RVA: 0x000588A4 File Offset: 0x00056AA4
	public void StartWander(Vector2 pos, float gage, float distanceThreshold)
	{
		this.nowPos = pos;
		this.wanderSpline.Init();
		this.wanderSpline.AddNode(this.nowPos);
		Vector2 checkPos = this.nowPos;
		for (int i = 0; i < this.wanderNum - 1; i++)
		{
			Vector2 vector = this.NextPos2(checkPos, gage, distanceThreshold);
			this.wanderSpline.AddNode(vector);
			checkPos = vector;
		}
		this.wanderSpline.BuildSpline();
		this.nextRate = 0f;
	}

	// Token: 0x06000E29 RID: 3625 RVA: 0x0005892C File Offset: 0x00056B2C
	public void Update(float animeSpeed, float changeSpeed, float gage, float distanceThreshold)
	{
		float num = changeSpeed * Time.deltaTime / (float)this.wanderNum;
		this.nextRate += num;
		float num2 = 0.5f;
		float num3 = 1f / (float)this.wanderNum;
		if (this.nextRate >= num2)
		{
			Vector3 position = this.wanderSpline.node[this.wanderSpline.nodeCount - 1].position;
			Vector3 pos = this.NextPos2(position, gage, distanceThreshold);
			this.nextRate = this.wanderSpline.RenewMove(pos, this.nextRate);
		}
		this.nowPos = this.wanderSpline.GetPosition(this.nextRate);
	}

	// Token: 0x06000E2A RID: 3626 RVA: 0x000589E8 File Offset: 0x00056BE8
	private Vector2 NextPos2(Vector2 checkPos, float gage, float threshold)
	{
		Vector2 vector = checkPos;
		for (float num = 0f; num < threshold; num = Vector2.Distance(checkPos, vector))
		{
			vector.x = UnityEngine.Random.Range(this.poseMin, this.poseMax);
			vector.y = gage + UnityEngine.Random.Range(this.strokeMin, this.strokeMax);
			vector.x = Mathf.Clamp(vector.x, -1f, 1f);
			vector.y = Mathf.Clamp(vector.y, -1f, 1f);
		}
		return vector;
	}

	// Token: 0x04000EA9 RID: 3753
	private float poseMin = -1f;

	// Token: 0x04000EAA RID: 3754
	private float poseMax = 1f;

	// Token: 0x04000EAB RID: 3755
	private float strokeMin = -0.5f;

	// Token: 0x04000EAC RID: 3756
	private float strokeMax = 0.5f;

	// Token: 0x04000EAD RID: 3757
	private RNS wanderSpline = new TNS();

	// Token: 0x04000EAE RID: 3758
	private float nextRate;

	// Token: 0x04000EAF RID: 3759
	private int wanderNum = 10;
}
